package com.springboot.show_web.config;

import com.springboot.show_web.filter.MyFilter;
import com.springboot.show_web.listener.MyListener;
import com.springboot.show_web.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * Created by yaosheng on 2019/11/9.
 */
@Configuration
public class MyServerConfig {
    //注册三大组件
    @Bean
    public ServletRegistrationBean myServlet() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean (new MyServlet (), "/myServlet");
        registrationBean.setLoadOnStartup (1);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean myFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean ();
        filterRegistrationBean.setFilter (new MyFilter ());
        filterRegistrationBean.setUrlPatterns (Arrays.asList ("/hello", "myServlet"));
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean myListener() {
        ServletListenerRegistrationBean<MyListener> registrationBean = new ServletListenerRegistrationBean<> ();
        return registrationBean;
    }
}